package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.TransferData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.AskQue;
import com.ruoyi.system.service.IAskQueService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 问题解决Controller
 * 
 * @author jzy
 * @date 2024-01-23
 */
@RestController
@RequestMapping("/question/que")
public class AskQueController extends BaseController
{
    @Autowired
    private IAskQueService askQueService;

    /**
     * 查询问题解决列表
     */
    @RequiresPermissions("question:que:list")
    @GetMapping("/list")
    public TableDataInfo list(AskQue askQue)
    {
        startPage();
        List<AskQue> list = askQueService.selectAskQueList(askQue);
        return getDataTable(list);
    }

    /**
     * 导出问题解决列表
     */
    @RequiresPermissions("question:que:export")
    @Log(title = "问题解决", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AskQue askQue)
    {
        List<AskQue> list = askQueService.selectAskQueList(askQue);
        ExcelUtil<AskQue> util = new ExcelUtil<AskQue>(AskQue.class);
        util.exportExcel(response, list, "问题解决数据");
    }

    /**
     * 获取问题解决详细信息
     */
    @RequiresPermissions("question:que:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(askQueService.selectAskQueById(id));
    }

    /**
     * 新增问题解决
     */
    @RequiresPermissions("question:que:add")
    @Log(title = "问题解决", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AskQue askQue)
    {
        return toAjax(askQueService.insertAskQue(askQue));
    }

    /**
     * 修改问题解决
     */
    @RequiresPermissions("question:que:edit")
    @Log(title = "问题解决", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AskQue askQue)
    {
        return toAjax(askQueService.updateAskQue(askQue));
    }

    /**
     * 删除问题解决
     */
    @RequiresPermissions("question:que:remove")
    @Log(title = "问题解决", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(askQueService.deleteAskQueByIds(ids));
    }

    /**
     * 解决问题
     */
    @PutMapping("/{id}")
    public AjaxResult resolveProblem(@PathVariable("id") Long id){
        return toAjax(askQueService.resolveProblem(id));
    }

    /**
     * 问题移交
     */
    @PutMapping("transfer")
    public AjaxResult transferQue(@RequestBody TransferData transferData) {
        askQueService.transferQue(transferData);
        return success();
    }


}
